<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.ld.com/shield/tags" prefix="shield"%>
<%@ taglib uri="http://www.ld.com/jsp/plugin" prefix="plugin"%>
<%@ taglib prefix="popup" uri="http://www.ld.com/jsp/popup/tags" %>
<%@ page trimDirectiveWhitespaces="true"%>
<fmt:setLocale value="zh_CN" />
<shield:permssion type="button">
	<form action="${ctxPathA}/system/dbbackup/backupSystem" method="post"
		autocomplete="off" class="show-info" successDo="backUpSuccess"  >
		<shield:token />
		<input id="id" name="id" type="hidden" maxlength="100"
			value="${model.id }">
		<table class="tab-show">
			<colgroup>
				<col width="20%">
				<col width="">
			</colgroup>
			<tr>
				<th><span style="color: red;">*</span> <label>连接：</label></th>
				<td>
				<select id="databaseConnId" name="dbConnId" >
            	<option value="0">本项目库</option>
    	<c:forEach var="dbset" items="${dbsets }">
    			<option value="${dbset.id}">${dbset.dbSetName }</option>
    	</c:forEach>
            	</select>
				</td>
			</tr>
			<tr>
				<th><span style="color: red;">*</span> <label>备份库选项：</label></th>
				<td>
					<input type="radio" name="backupType" value="database" class="radio backupType" checked="checked"   >全库备份	<input type="radio" name="backupType" value="table" class="radio backupType" >表备份
				</td>
			</tr>
				<tr id="backUptablesArgs" style="display: none">
         		 <th><span style="color: red; ">*</span><label>备份表选项：</label></th>
                     <td>
                           <input type="radio" name="tablesArgs" value="contain" class="radio" checked="checked"   >包含	<input type="radio" name="tablesArgs" value="ignore" class="radio" >忽略
                     </td>
            </tr>
			<tr id="backUptablesContent" style="display: none">
         		 <th><label id="tablesLabel">备份表：</label></th>
                     <td>
                          <popup:popup url="${ctxPathA}/popup/dbbackup/tables/toSearch" multi="true" hasOrder="true"
                             fileId="tableId" fileName="tables" width="200" viewTitle="选择备份表"   paramSelector="#databaseConnId"/>
                     </td>
            </tr>
			<tr >
         		 <th><span style="color: red; ">*</span><label>备份项：</label></th>
                   	 <td>
                        <input type="radio" name="dbHandler" value="all" class="radio" checked="checked"   >全部<input type="radio" name="dbHandler" value="structure" class="radio" >仅结构<input type="radio" name="dbHandler" value="data" class="radio" >仅数据
                     </td>
            </tr>
	
		</table>
		<div class="taCenter">
			<input class="button" type="submit" value="备份" /> <input
				class="button default" type="reset" value="重置" />
		</div>
	</form>
</shield:permssion>
<script>
	$(function(){
		$(":radio.backupType").click(function(){
			if($(this).val()=='table'){
				$("#backUptablesContent").show();
				$("#backUptablesArgs").show();
				$("#tablesLabel").before("<span style=\"color: red;\">*</span>");
				$("#tables").addClass("required");
				$("#tables").removeClass("ignore");				
			}else if($(this).val()=='database'){
				$("#backUptablesContent").hide();
				$("#backUptablesArgs").hide();
				$("#tablesLabel").prev().remove();
				$("#tables").addClass("ignore");
			}
		});
		
	});
	
	function backUpSuccess(data)
	{
		ShieldJS.openDialog("${ctxPathA}/system/dbbackup/process", {}, function (ele, dialog, index) {
			 time=setInterval(function(){
				setProcess(ele);
			}, 100);
		});
	}
	function setProcess(ele){ 
		$.ajax({
			type: "POST",
	 		url: "${ctxPathA}/system/dbbackup/getProcess",
	 		data:{type:0},
	 		success: function(mg){     
	         console.log(mg);
	         if(mg.success&&mg.data)
	       	 {
	       	     ele.find("#processbar").val(mg.data.percent);
	             ele.find("#processvalue").text(mg.data.content);
	             ele.find("#backnumvalue").text("("+mg.data.backnum+")");
	             if(mg.data.backstatus==1){
	            	 $(".searchForm").submit();
	           	   clearInterval(time);
	           	 }else if(mg.data.backstatus==-1){
	             	   clearInterval(time);
	             }
	       	 }
	       
	      }
	   }); 	
		
	} 
</script>